<?php
class Commodity_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
    }
    

    function searchList(){
    	$query = "SELECT * FROM COMMODITY_HEADER ";
    	return $this->db->query($query)->result();
    }

    function searchLists($arr){
    	$query = "SELECT CH.*,CD.* FROM COMMODITY_HEADER CH INNER JOIN COMMODITY_DETAIL CD
    			ON CH.SHOP_CODE=CD.SHOP_CODE AND CH.COMMODITY_CODE = CD.COMMODITY_CODE
    			WHERE CD.SHOP_CODE = ?   " ;
    			
    	$param = array('0000');
    	if(!empty($arr["s_commoditycode_from"])) {
    		$query = $query." AND CH.COMMODITY_CODE >=  ? ";
    		array_push($param,$arr["s_commoditycode_from"]);
    	}
    	if(!empty($arr["s_commoditycode_to"])) {
    		$query  = $query. " AND CH.COMMODITY_CODE <=  ? ";
    		array_push($param,$arr["s_commoditycode_to"]);
    	}
    	if(!empty($arr["s_skucode"])) {
    		$query  = $query. " AND CD.SKU_CODE = ? ";
    		array_push($param,$arr["s_skucode"]);
    	}

		echo $query;
    	var_dump($param);
    	
    	return $this->db->query($query,$param)->result();
    	 
    }

    
    function search_detail($sku_code){
    	$query = "SELECT CH.*,CD.* FROM COMMODITY_HEADER CH INNER JOIN COMMODITY_DETAIL CD
    			ON CH.SHOP_CODE=CD.SHOP_CODE AND CH.COMMODITY_CODE = CD.COMMODITY_CODE
    			WHERE CD.SHOP_CODE = ? AND CD.COMMODITY_CODE = ? LIMIT 1 " ;
    	//return $this->db->query($query)->result();
    	//return $this->db->query($query, array($shop_code, '$sku_code))->result();
    	return $this->db->query($query, array('0000', $sku_code))->row();
    }
    
    
}